<?php
require_once (HOME.'include/base/FrontendController.php');
class test extends FrontendController {
	function __construct() {
		$this->test ();
	}
	function test() {
		parent::__construct ();
	} // end construct
	function index() {
		$articletitle = spClass ( 'm_article' )->find ( array (
				'article_id' => '1' 
		), 'post_time DESC', 'title,content' );
		
		dump($articletitle);
		$title = $articletitle ['title'];
		$this->assign ( 'tpl_title', $title );
		$this->assign ( 'article_content', $articletitle ['content'] );
		$this->display ( 'article.content.layout.html' );
	}
	
	function showcaptcha(){
		import('library/captcha.php');
		$captcha = new SimpleCaptcha();
		$captcha->resourcesPath = HOME.'include/library/resources';
		$captcha->imageFormat = 'png';
		$captcha->blur = true;
		$captcha->CreateImage();
		
		if (isset($_GET['captcha']))
		{
			if ( $_GET['captcha'] == $_SESSION['captcha'] )
			{
				echo 'right';
			}
		}
		echo "danteng";
	}
	
	function checkCaptcha(){
		if(false){
			return false;
		}else {
			
			if ( $this->spArgs('captcha') == isset($_SESSION['captcha']) ? $_SESSION['captcha'] : false )
			{
				return true;
			}
		}
	}
	
	function testCaptcha(){
		dump($_SESSION);
		if ($this->checkCaptcha() )
		{
			echo 'right';
		}
	}
	
	function testspArg(){
// 		spClass('sptest')->test();
			dump ( $this->spArgs('ajax',FALSE,'ajax') );
			$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';

			dump(json_decode($json));
			dump(json_decode($json, true));

	}
	
	function testXml(){
		import('utils/spXml.php');
		$x = spClass('spXml');
		$x->test = array(
				'name' => 'sienus',
				'type' => '1',
				'age' => '11'
				);
		echo $x->xml();
	}

	function testAjax(){
	$result = $this->spAjax('ajax',FALSE,'json');
		dump($result);
	}
	
	function testRecursion(){
		$result = spClass('m_acategory')->spLinker()->findAll();
		dump($result);
	}
	
	function testError(){
		$this->error('xxxfkdjlf');
	}
	
	function testjstree(){
		$mod_department = spClass('m_department');
		$mod_department->linker[0]['enabled'] = FALSE;
		$mod_department->linker[1]['enabled'] = FALSE;
		$mod_department->linker[2]['enabled'] = FALSE;
		$result = $mod_department->spLinker()->findAll();
		dump( $result );
		dump( json_encode($result));
	}
}

class sptest{
	function test(){
		echo "spClass test ok!";
	}
}
?>